<template>
  <el-dropdown trigger="click" @command="handleSetLanguage">
    <div class="language-select">
      {{ language === 'zh-cn' ? '简体中文' : '繁體中文' }}
      <i class="el-icon-arrow-down el-icon--right"></i>
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item :disabled="language==='zh-cn'" command="zh-cn">
        简体中文
      </el-dropdown-item>
      <el-dropdown-item :disabled="language==='zh-tw'" command="zh-tw">
        繁體中文
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  name: 'LangSelect',
  computed: {
    language() {
      return this.$i18n.locale
    }
  },
  methods: {
    handleSetLanguage(lang) {
      this.$i18n.locale = lang
      this.$message({
        message: '切换语言成功',
        type: 'success'
      })
    }
  }
}
</script>

<style scoped>
.language-select {
  cursor: pointer;
  font-size: 14px;
  color: #5a5e66;
  padding: 0 8px;
}
</style> 